package com.tjc.media.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.tjc.media.domain.SongInfo;
import com.tjc.media.service.ISongInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 歌曲信息Controller
 * 
 * @author 大根教会
 * @date 2025-09-23
 */
@RestController
@RequestMapping("/media/songInfo")
public class SongInfoController extends BaseController
{
    @Autowired
    private ISongInfoService songInfoService;

    /**
     * 查询歌曲信息列表
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SongInfo songInfo)
    {
        startPage();
        List<SongInfo> list = songInfoService.selectSongInfoList(songInfo);
        return getDataTable(list);
    }

    /**
     * 导出歌曲信息列表
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:export')")
    @Log(title = "歌曲信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SongInfo songInfo)
    {
        List<SongInfo> list = songInfoService.selectSongInfoList(songInfo);
        for(SongInfo songData : list) {
            songData.setSongAlbumName(songData.getSongAlbum() == 1?"赞美诗":"青年诗歌");
        }
        ExcelUtil<SongInfo> util = new ExcelUtil<SongInfo>(SongInfo.class);
        util.exportExcel(response, list, "歌曲信息数据");
    }

    /**
     * 获取歌曲信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:query')")
    @GetMapping(value = "/{songId}")
    public AjaxResult getInfo(@PathVariable("songId") Long songId)
    {
        return success(songInfoService.selectSongInfoBySongId(songId));
    }

    /**
     * 新增歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:add')")
    @Log(title = "歌曲信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated SongInfo request)
    {
        return toAjax(songInfoService.insertSongInfo(request));
    }

    /**
     * 修改歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:edit')")
    @Log(title = "歌曲信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@Validated SongInfo request)
    {
        return toAjax(songInfoService.updateSongInfo(request));
    }

    /**
     * 删除歌曲信息
     */
    @PreAuthorize("@ss.hasPermi('media:songInfo:remove')")
    @Log(title = "歌曲信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{songIds}")
    public AjaxResult remove(@PathVariable Long[] songIds)
    {
        return toAjax(songInfoService.deleteSongInfoBySongIds(songIds));
    }
}
